﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="taskMsgContent.aspx.cs" Inherits="ZX.WebApp.EHR.taskMsgContent" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>预警内容</title>
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../Scripts/Public.js" type="text/javascript"></script>
    <script type="text/javascript">
        var tabelName;
        $(document).ready(function () {
            tabelName = getPar1("datatableName"); //数据表名
            //alert("tabelName:" + tabelName);
            if (tabelName != undefined && tabelName != "") {
                //根据实体名获取字段
                var url = "../EHR/DatPostAjax.aspx?flag=getfieldbytable&table=" + tabelName;
                $.ajax({
                    type: 'get',
                    url: url,
                    dataType: "json",
                    success: function (data) {
                        for (var i = 0; i < data.length; i++) {
                            addtr(data[i]);
                        }
                        if (data.length == 0) {
                            //$("#tbcondition tbody tr").remove();
                            deltr();
                        }
                    },
                    error: function (data) {
                    }
                });
            }
            else {
                //$("#tbcondition tbody tr").remove();
                deltr();
            }

            //全选,全不选
            $("#chkAll").click(function () {
                //遍历tr
                //alert($("#chkAll").attr("checked"));
                if (!$("#chkAll").attr("checked")) {
                    //全选
                    $("#tbcondition tr").first().nextAll().each(function () {
                        $(this).addClass("selectedTr").find(":checkbox").attr("checked", true);
                    });
                }
                else {
                    //全不选
                    $("#tbcondition tr").first().nextAll().each(function () {
                        $(this).removeClass("selectedTr").find(":checkbox").attr("checked", false);
                    });
                }
            });

            //确定按钮
            var strJson = "{\"Content\":[";
            var strtaskMsgCNContent = "";
            var strtaskMsgENContent = "";
            parent.$("#okay").mousedown(function () {
                //遍历tr
                var $trs = $("#tbcondition").find("tr");
                for (var i = 2; i < $trs.length; i++) {
                    var $tr = $trs.eq(i);
                    if ($tr.hasClass("selectedTr")) {
                        var FieldEName = $tr.find("input[name=FieldEName]").val();
                        var FieldCName = $tr.find("input[name=FieldCName]").val();
                        var FieldSeq = $tr.find("input[name=FieldSeq]").val();
                        strJson += "{\"FieldEName\":'" + FieldEName + "\",\"FieldCName':\"" + FieldCName + "\",\"FieldSeq\":\"" + FieldSeq + "\"},";
                        strtaskMsgCNContent += "[" + FieldCName + "]";
                        strtaskMsgENContent += "[" + FieldEName + "]";
                    }
                }
                strJson = strJson.substr(0, strJson.length - 1);
                strJson += "]}";
                parent.taskMsgCNContent = strtaskMsgCNContent;
                parent.taskMsgENContent = strtaskMsgENContent;
            });
        });

        //增加行
        function addtr(data) {
            var tr = $("#tbcondition tr").eq(1).clone();
            tr.show();
            tr.appendTo("#tbcondition").removeClass("selectedTr").find(":checkbox").attr("checked", false);
            var FieldEName = $("input[name=FieldEName]:last");
            var FieldCName = $("input[name=FieldCName]:last");
            var FieldSeq = $("input[name=FieldSeq]:last");
            FieldEName.attr("readonly", "readonly");
            FieldEName.css("background", "whitesmoke");
            FieldCName.attr("readonly", "readonly");
            FieldCName.css("background", "whitesmoke");
            FieldEName.val(data.FieldEName);
            FieldCName.val(data.FieldCName);
            FieldSeq.val(data.FieldSeq);
        }

        //删除行
        function deltr() {
            //遍历tr
            $("#tbcondition tr").first().nextAll().each(function () {
                if ($(this).hasClass("selectedTr")) {
                    $(this).remove();
                }
            });
        };

        //删除所有行
        function deltr() {
            //遍历tr
            $("#tbcondition tr").first().nextAll().each(function () {
                $(this).remove();
            });
        };

        //选中行
        $("#tbcondition tr").live("click", function () {
            if ($(this).hasClass("selectedTr")) {
                $(this).removeClass("selectedTr").find(":checkbox").attr("checked", false);
                $("#chkAll").attr("checked", false);
            }
            else {
                $(this).addClass("selectedTr").find(":checkbox").attr("checked", true);
                var ischkAll = true;
                $("#tbcondition tr").first().nextAll().each(function () {
                    if (!$(this).hasClass("selectedTr")) {
                        ischkAll = false;
                    }
                });
                if (ischkAll) {
                    $("#chkAll").attr("checked", true);
                }
            }
        });
    </script>
    <style type="text/css">
        body{font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;color: #333333;background-color: #FFFFFF;} 
        select{width:99%;} 
        td { border: 1px solid #CCCCCC;}
        .textarea{ width: 96%;height: 25px;}	
        .selectedTr{  background-color: blue;} 
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table align="center" border="1" id="tbcondition" name="tbcondition" style="border-collapse: collapse" width="99%">
            <tbody>
                <tr id="data_head" style="background-color: #e4e7e2">
                   <td style="text-align: center"><input type="checkbox" id="chkAll" name="chkAll" /></td>
                    <td style="text-align: center">参数英文名</td>
                    <td style="text-align: center">参数中文名</td>
                    <td style="text-align: center;display:none">排序</td>
                </tr>
			<tr id="data_row" style="display:none">
                <td>
                    <input type="checkbox" id="chktr" name="chktr" />
                </td>
				<td>
					<input id="FieldName" name="FieldEName" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; width: 100%; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" title="参数英文名" type="text" value="" />
                </td>
				<td>
					<input id="FieldCName" name="FieldCName" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; width: 100%; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" title="参数中文名" type="text" value="" />
                </td>
				<td style="display:none">
					<input id="FieldSeq" name="FieldSeq" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; width: 100%; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" title="排序" type="text" value="" />
                </td>
			</tr>
            </tbody>
        </table>
    </div>
    </form>
</body>
</html>